package test.utils;

import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import java.net.URI;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : example
 * @ Author: XuLeHuang
 * @ Date: 2022/10/3 10:52
 * @ Description:
 */
public class JavaSourceFileObject extends SimpleJavaFileObject {
    private CharSequence content;

    JavaSourceFileObject(String className, CharSequence content) {
        super(URI.create("string:///" + className.replace('.', '/')
                        + JavaFileObject.Kind.SOURCE.extension),
                JavaFileObject.Kind.SOURCE);
        this.content = content;
    }

    @Override
    public CharSequence getCharContent(boolean ignoreEncodingErrors) {
        return content;
    }
}
